package com.compass.mobile.ui.dialog

import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import com.compass.mobile.databinding.DialogCustmoerServiceBinding
import com.compass.mobile.framework.base.BaseDialog
import com.compass.mobile.framework.base.BaseDialogFragment
import com.compass.mobile.framework.constant.BACKSPACE_ACTION
import com.compass.mobile.framework.constant.CANCEL_ACTION
import com.compass.mobile.framework.constant.CLINICAL_RECEPTION
import com.compass.mobile.framework.constant.END_ACTION
import com.compass.mobile.framework.constant.INQUIRY_ACTION
import com.compass.mobile.framework.constant.REFERRAL_ACTION
import com.compass.mobile.framework.constant.selfServicePhone
import com.compass.mobile.framework.constant.selfServiceWxCode
import com.compass.mobile.framework.ext.onClick
import com.compass.mobile.framework.utils.FocusViewUtils
import com.compass.mobile.framework.utils.QRCodeDealUtils
import com.compass.mobile.ui.activity.OrderDetailsActivity
import dp2px

/**
 * Description： 问诊单dialog
 * Date:2024/7/8 20:12
 */
class OrderCodeDialog {
    class Builder(
        activity: FragmentActivity,
        private var orderId: String?,
        private var type: String?,
        private var action: String
    ) :
        BaseDialogFragment.Builder<Builder>(activity) {
        private val mBinding: DialogCustmoerServiceBinding =
            DialogCustmoerServiceBinding.inflate(LayoutInflater.from(activity))

        init {
            initView()
        }

        private fun initView() {
            setContentView(mBinding.root)
            setWidth(ViewGroup.LayoutParams.WRAP_CONTENT)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setAnimStyle(BaseDialog.AnimStyle.DEFAULT)
            setGravity(Gravity.CENTER)
            setCancelable(true)
            FocusViewUtils.scaleView(mBinding.tvToOrder, 2)
            mBinding.tvToOrder.requestFocus()
            mBinding.tvToOrder.text = "查看订单"
            mBinding.tvPhone.text = "客服电话：${UserInfoManager.getString(selfServicePhone)}"
            setTips()
            mBinding.imgWxCode.setImageBitmap(
                QRCodeDealUtils.generateQRCodeWithoutMarginBlack(
                    UserInfoManager.getString(selfServiceWxCode),
                    dp2px(400f),
                    dp2px(400f)
                )
            )
            mBinding.tvToOrder.onClick {
                dismiss()
                //跳转到我的订单详情
                OrderDetailsActivity.start(context, orderId)
            }
        }

        private fun setTips() {
            when (action) {

                //接诊
                CLINICAL_RECEPTION->{
                    when (type) {
                        "1" -> {
                            mBinding.refusalInfo.text =
                                "温馨提示：医生已接诊您的订单！点击下方按钮可查看订单详情。"
                        }

                        "2" -> {
                            mBinding.refusalInfo.text =
                                "温馨提示：医生已接诊您的订单！将在15分钟内向您拨打电话，号码为029开头请注意接听。点击下方按钮可查看订单详情"
                        }

                        "3" -> {
                            mBinding.refusalInfo.text =
                                "温馨提示：医生已接诊您的订单！将在15分钟内向您发起视频，请注意接听。点击下方按钮可查看订单详情。"
                        }

                    }
                }

                //订单支付成功
                INQUIRY_ACTION -> {
                    //1-图文 2-语音 3-音视频
                    when (type) {
                        "1" -> {
                            mBinding.refusalInfo.text =
                                "温馨提示：您的问诊订单支付成功！点击下方按钮可查看订单详情。"
                        }

                        "2" -> {
                            mBinding.refusalInfo.text =
                                "温馨提示：您的问诊订单支付成功！医生接诊后,将在15分钟内向您拨打电话，号码为029开头请注意接听。点击下方按钮可查看订单详情"
                        }

                        "3" -> {
                            mBinding.refusalInfo.text =
                                "温馨提示：您的问诊订单支付成功！医生接诊后,将在15分钟内向您发起视频，请注意接听。点击下方按钮可查看订单详情。"
                        }

                    }
                }

                //转诊action
                REFERRAL_ACTION -> {
                    mBinding.refusalInfo.text =
                        "温馨提示：医生已将您的问诊单转给其他医生。点击下方按钮可查看订单详情。"
                }
                //问诊自动取消
                CANCEL_ACTION -> {
                    mBinding.refusalInfo.text =
                        "温馨提示：您的订单由于医生长时间未接诊，现在已为您自动取消！您可选择其他医生问诊。点击下方按钮可查看订单详情。"
                }
                //退诊
                BACKSPACE_ACTION -> {
                    mBinding.refusalInfo.text =
                        "温馨提示：医生已将您的问诊单退诊。点击下方按钮可查看订单详情。"
                }
                //结束问诊
                END_ACTION -> {
                    mBinding.refusalInfo.text =
                        "温馨提示：医生已结束了您的问诊！点击下方按钮可查看订单详情"
                }


            }

        }

    }
}
